<?
require 'global.php';
$url='profile';

if($customer_id==0) { header('Location:login.html'); exit; }
$gee=$customer;
// 错误集 error array
$errors=array();

$action='you guess';
if(isset($_POST["action"]) && $_POST["action"]!="")$action=clean($_POST["action"]);
if($action=='update'){
	$key='you guess'; // safety key 安全码, 过滤非法提交
	if(isset($_POST["key"]) && $_POST["key"]!="") $key=clean($_POST["key"]);
	if($key != md5('ecomgear'.date('Ymd'))){ exit; }

	$nickname='';
	if(isset($_POST["nickname"]) && $_POST["nickname"]!="") $nickname=clean($_POST["nickname"]);
	if($nickname==''){ wheel('./'); exit; }

	$arr=array(
		'nickname'=>$nickname,
		'gender'=>$_POST['gender'],
	);
	if(isset($_POST["firstname"]) && $_POST["firstname"]!="") $arr['first_name']=clean($_POST["firstname"]);
	if(isset($_POST["lastname"]) && $_POST["lastname"]!="") $arr['last_name']=clean($_POST["lastname"]);
	if(isset($_POST["birthday"]) && $_POST["birthday"]!="") $arr['birthday']=clean($_POST["birthday"]);
	if(isset($_POST["mobile"]) && $_POST["mobile"]!="") $arr['mobile']=clean($_POST["mobile"]);
	if(isset($_POST["phone"]) && $_POST["phone"]!="") $arr['phone']=clean($_POST["phone"]);

	//pre($arr); exit;
	try{
		$gee->update($arr,'id',$customer_id);
		//yell('Success! ', 'profile.php');
		$errors[]=array('message'=>WEB_UPDATED_SUCCESSFULLY,'type'=>'message','url'=>'profile.php');
	}
	catch(Exception $e){
		//yell('Failed, retry.', 'profile.php');
		$errors[]=array('message'=>WEB_UPDATE_FAILED,'type'=>'alert','url'=>'profile.php');
	}
}

$info=$customer->get_row($customer_id);

// SEO 
$cate_name=WEB_PERSONAL_PROFILE;
$title=$cate_name.' - '.$config['SITE_COMPANY_'.LANG];
$dpn=$kwd=$title;

// view 加载视图
require VIEW.$url.'.php';

// end of file
